package org.example.com.kotlinlab.delegate.property_delegate.local_variable_delegate

class LocalVariableDelegate01 {
}
class Foo {
    fun isValid(): Boolean {
        return true
    }

    fun doSomething() {
        println("Foo doSomething..")
    }
}

fun exam(computeFoo: () -> Foo) {
    val memorizedFoo by lazy {
        println("init")
        computeFoo()
    }

    /**
     * 1.memorizedFoo只会在第一次访问时计算
     * 2.someCondition为false时，memorizedFoo不会进行计算
     */
    val someCondition = false
    if (someCondition && memorizedFoo.isValid()) {
        memorizedFoo.doSomething()
    }
    println(memorizedFoo)
}

fun main() {
    exam {
        Foo()
    }
}